#include <string.h>
#include <stdio.h>
#include "ff_publog.h"

void printBuffer(unsigned char *pBuffer, int nSize, const  char *tag){
    char loghex[2000];
    char logchar[2000];
    char logtemp[10] = {0};
    memset(loghex,0,sizeof(loghex));
    memset(logchar,0,sizeof(logchar));
    memset(logtemp,0,sizeof(logtemp));
    char temphex[4],tempchar[2];
    for(int i=0; i<nSize+1; i++){
        if((i!=0 && i%16==0) || (i==(nSize-1))){
            if(i!=(nSize-1)){
                DPrint("%s %s  %s\n",tag,loghex,logchar);
            }
            else{
                for(int x=0; x<(16-i%16); x++){
                    sprintf(logtemp,"   ");
                    strcat(loghex,logtemp);
                }
                DPrint("%s %s  %s\n",tag,loghex,logchar);
            }
            memset(loghex,0,sizeof(loghex));
            memset(logchar,0,sizeof(logchar));
        }
        sprintf(temphex, "%02x ", pBuffer[i]);
        if((pBuffer[i]>='0' && pBuffer[i]<='9') || (pBuffer[i]>='a' && pBuffer[i]<='z') || (pBuffer[i]>='A' && pBuffer[i]<='Z'))
           sprintf(tempchar, "%c", pBuffer[i]);
        else
           sprintf(tempchar, "%c", '.');
        strcat(loghex,temphex);
        strcat(logchar,tempchar);
   }
}

